package com.goparry.taskman.notes;

import java.io.File;
import java.io.IOException;

import com.goparry.taskman.R;
import com.goparry.taskman.TaskManUtils;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class TextNoteActivity extends Activity implements Button.OnClickListener {
	TextView mLabel;
	
    @Override
	public void onCreate(Bundle icicle){ 
		super.onCreate(icicle); 
		
		// Set the layout for this tab to docs.xml
		// This is a place holder for a home page
		setContentView(R.layout.textnote);
		// Configure the  buttons
		Button btn = (Button)findViewById(R.id.btntextnotesave);
		btn.setOnClickListener(this);
		btn = (Button)findViewById(R.id.btntextnotecancel);
		btn.setOnClickListener(this);

	}
	@Override
	public void onClick(View view) {
		int viewID = view.getId();
		if (viewID==R.id.btntextnotecancel) {
			this.finish();
		} else if (viewID==R.id.btntextnotesave) {
			EditText textView = (EditText)findViewById(R.id.textnote);
			File file;
			try {
				file = TaskManUtils.createTempFile(getFilesDir().getAbsolutePath(), "note.txt", textView.getText().toString());
				Intent intent = this.getIntent();
				intent.putExtra("TASK_NOTE_FILE", file.getAbsolutePath());
				this.setResult(RESULT_OK, intent);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			this.finish();
		}
	} 

}
